package com.ruoyi.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：jiangguanjun
 * @description：bean转换
 * @date ：2020/8/1 11:44
 */
public class MyBeanUtils {

    /**
     * @description List集合转换 将Listde
     * @param source
     * @param clazz
     * @param <E>
     * @param <T>
     * @return
     */
    public static <E, T> List<T>   convert2OtherCollection(List<E> source, Class clazz) throws IllegalAccessException, InstantiationException {

            List<T> list = new ArrayList<>( ) ;
        for (E e:source) {
            T t = (T) clazz.newInstance();
            BeanUtils.copyProperties(e,t);
            list.add(t) ;
        }

        return list ;
    }
}
